#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   real_execl.py    
@Contact :   raogx.vip@hotmail.com
@License :   (C)Copyright 2017-2018, Liugroup-NLPR-CASIA

@Modify Time      @Author    @Version    @Desciption
------------      -------    --------    -----------
2020/10/5 9:49 下午   gxrao      1.0         None
'''

# import lib
import pandas as pd


def read_execl_by_col(path, col):
    """
    获取对应列中的数据
    :param path:execl文件路径
    :param col:指定列名
    :return:
    """
    data = pd.DataFrame(pd.read_excel(path))
    return data[col]


def merge_two_columns_by_key(data, key1, key2, new_key, is_delete):
    """
    合并两列数据成为一列新数据
    :param data: 元数据 dataframe
    :param key1: 合并列1
    :param key2: 合并列2
    :param new_key: 新列表
    :param is_delete: 是否删除被合并的列
    :return: 新数据 dataframe
    """
    if new_key == "":
        new_key = key1 + '_' + key2

    data[key1] = data[key1].astype(str)
    data[key2] = data[key2].astype(str)
    data[new_key] = data[key1] + data[key2]
    if is_delete:
        data = data.drop([key1, key2], axis=1)
    return data


def get_sequence_info_by_key(data, group_key, info_key):
    """
    获取时序数据
    :param data: 元数据 dataframe
    :param group_key: 时序数据key
    :param info_key: 时序结果key
    :return: 时序结果字典
    """
    data = data.groupby(group_key)
    result = {}
    for group_key, group_value in data:
        items = []
        for index, row in group_value.iterrows():
            item = str(row[info_key])
            flag = item.find(',')
            items.append([int(row[info_key][1:flag]), int(row[info_key][flag + 1:len(row[info_key]) - 1])])
        result[group_key] = items
    return result
